package com.XinYun.Library.modules.person;

import com.XinYun.Library.modules.commons.BasicServlet;
import com.XinYun.Library.modules.person.Service.SqlServiceImpl;
import com.XinYun.Library.utils.HTTPRequestUtils.HTTPRequestUtil;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "changeServlet", value = "/changeServlet")
public class changeServlet extends HttpServlet {//修改邮箱
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String json = HTTPRequestUtil.getBody(req);
        //将JSON字符转化为JAVA对象
        System.out.println(req.getContextPath());
        JSONObject jsonObject = JSONObject.parseObject(json);
        String value = jsonObject.getString("uid");
        String value1 = jsonObject.getString("mail");
        SqlServiceImpl service =new SqlServiceImpl();
        if(value.equals(""))
        {
            jsonObject.put("code",-1);
            jsonObject.put("message","uid为空");
        }if(value1.equals(""))
        {
            jsonObject.put("code",-1);
            jsonObject.put("message","mail为空");
        }else{
        service.change1(value,value1);
            jsonObject.put("code",1);
            jsonObject.put("message","修改邮箱成功");
        }
        PrintWriter writer = resp.getWriter();
        writer.println("修改成功");
        resp.getWriter().write(jsonObject.toString());
    }
}
